
#ifndef __ROOT_H__
#define __ROOT_H__

#include "sys_port.h"
#include "page_base.h"
#include "page_manager.h"
#include "list.h"

#include "ui_base_page.h"
#include "midea_collection_view.h"
#include "midea_collection_dynamic.h"
#include "../base_scroll_ui/midea_flex.h"
#include "../base_scroll_ui/midea_base_scroll_tool.h"
#include "../base_scroll_ui/midea_base_scroll_cell.h"

#define  DEV_WORK                  (0)
#define  DEV_OFF                   (1)
#define  DEV_OFF_LINE              (2)

#define  P_LEN                     (128)
#define  R_N_LEN                   (128)

#define  PAGE_SETTING_ID            (0)
#define  PAGE_HOME_ID               (1)
#define  PAGE_SETTING_NAME          ("setting")
#define  PAGE_HOME_NAME             ("home")

#define  THE_SETTING                ("device_setting")
#define  THE_DEVICE                 ("device_collec_view")

typedef enum {
    UI_TYPE_SETTING = 0,
    UI_TYPE_SETTING2,

    UI_TYPE_SCENE,
    UI_TYPE_HOME,

    UI_TYPE_DEV_SW,
    UI_TYPE_DEV_DW,

    UI_TYPE_DEV_OC,
    UI_TYPE_DEV_JC,
    UI_TYPE_DEV_MC,

    UI_TYPE_DEV_PURI,
    UI_TYPE_DEV_WASHER,
}ui_type_e;

typedef enum {

    MSG_DOWNLOAD_FIRMWARE = 0xf001,
    
    MSG_SYS_UP_ERR,       
    MSG_SYS_UP_SUCCEED,   

    MSG_E1,
    MSG_ERR,
    MSG_MATER,
    MSG_TELEPHONE,
    MSG_UPDATE,

    MSG_VOICE_INPUT,
    MSG_VOICE_MEETING,
    MSG_VOICE_OUTPUT,
    MSG_VOICE_SUNNY,
    MSG_VOICE_WKUP,

    MSG_KEY_LEFT,         
    MSG_KEY_RIGHT,        
    MSG_KEY_MID,          

    MSG_IDLE_EVENT,

    MSG_HUMAN_COMING,
    MSG_HUMAN_LEAVE,

    MSG_LIGHT_UPDATE,

    MSG_SCR_OFF,

} sys_msg_e; 


#define IDLE_TIME      (15*1000)  // (5*60*1000)     // 弹出屏保时间，单位：ms。

typedef struct _event_info_t
{
    int  event_code;
    int  event_para;
    char dev_name[128];
    char dev_consum_name[128];
    char dev_err_code[24];
    char dev_err_info[128];
}event_info_t;

typedef struct {
    page_vtable_t* method;
    void*          priv_data;
}dev_info_t;

typedef struct 
{
    char name[R_N_LEN];
    char id[R_N_LEN];
    char type[R_N_LEN];
    char subtype[R_N_LEN];
} device_t;

typedef struct  {
	slist_t 	e_tail;
    device_t    e_attr;
}device_link_t;

typedef struct 
{
    char name[R_N_LEN];
    char id[R_N_LEN];
    char type[R_N_LEN];
    char subtype[R_N_LEN];
    
    dev_info_t* dev;
} root_page_t;

typedef struct  {
	slist_t 	e_tail;
    root_page_t e_attr;
}root_link_t;

typedef struct 
{
    int          gesture_state;
    int          cur_id;
    int          is_idle;
    int          len;
    slist_t    * e_head;
    slist_t    * dev_head;

    lv_timer_t * time;
    lv_timer_t * idle_timer;
    lv_timer_t * scr_off_timer;
    lv_timer_t * sleep_timer;

    lv_timer_t * early_timer;
    lv_timer_t * update_timer;

    lv_timer_t * delay_timer;
} root_ctl_t;


typedef struct
{
    void (*on_page_create) (lv_obj_t* parent,void* ui_data);
    void (*on_page_destroy)(void* ui_data);
    void (*on_page_update) (void* ui_data);
} page_method_t;

typedef struct
{
    void*          data;
    page_method_t* method;
}page_info_t;

int root_ctl_init(void);
int root_ctl_preinit(void);
int root_send_msg(int cmd,int d0,int d1,int d2,void* arg);

int root_gesture_state(void);
int root_gesture_enable(void);
int root_gesture_disable(void);

int root_idle_time_reset(void);
int root_exit_idle(void);

uint8_t root_scr_off_timer_interval_get(void);
uint8_t root_scr_off_timer_interval_set(uint8_t val);

int root_no_scr_off_flag_get(void);
int root_no_scr_off_flag_set(int val);
int root_page_enter_home(page_load_anim_t type);

static int root_page_add(char* name,char* id,char* type,char* subtype,dev_info_t* dev);
       int root_page_del(char* name,char* id);

root_link_t* root_page_find_index(int index);
root_link_t* root_page_find_bydevid(const char* devid);
int root_page_add_all_device(void);
int root_page_del_all_device(void);
int root_page_get_num(void);
int root_page_get_devnum(void);

int root_page_device_trav(void);

int root_gesture_top(void);
int root_gesture_bottom(void);

#endif
